//
//  KLCollectionGoodTableViewCell.m
//  KunLun
//
//  Created by Mac on 2017/11/28.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "BLShopCarTableViewCell.h"
#import "STAutoAddView.h"
@interface BLShopCarTableViewCell()
@property(nonatomic, strong) UIImageView                     *iconImageView;
@property(nonatomic, strong) STLabel                     *titleLable;
@property(nonatomic, strong) STLabel                     *guigeLable;
@property(nonatomic, strong) STLabel                     *typeLable;//规格
@property(nonatomic, strong) STLabel                     *moneyLable;



@end
@implementation BLShopCarTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
+ (CGFloat)cellHeight{
    return 135;
}
#pragma mark --subView
- (void)configSubView{
    
    self.chosedButton = [[STButton alloc] initWithFrame:CGRectMake(10, 0, 44, 44)
                                                  title:nil
                                             titleColor:nil
                                              titleFont:0
                                           cornerRadius:0
                                        backgroundColor:nil
                                        backgroundImage:nil
                                                  image:[UIImage imageNamed:@"购物未选中"]];

    [self.chosedButton setImage:[UIImage imageNamed:@"购物选中"] forState:UIControlStateSelected];
    self.chosedButton.centerY = [BLShopCarTableViewCell cellHeight]/2;
    [self addSubview:self.chosedButton];
    
    
    self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.chosedButton.right , 10, 80, 100)];
    self.iconImageView.image = [UIImage imageNamed:@"个人头像"];
    self.iconImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.iconImageView.clipsToBounds = YES;
    [self addSubview:self.iconImageView];
    
    self.titleLable = [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 5, self.iconImageView.top , UIScreenWidth - 20 - self.iconImageView.right, 25)
                                                text:@"床单"
                                           textColor:KL_secendTextColor
                                                font:13
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];
    self.titleLable.numberOfLines = 0;
    [self addSubview:self.titleLable];
    
    STLabel * guigeLable = [[STLabel alloc] initWithFrame:CGRectMake(self.titleLable.left, self.titleLable.bottom  +5 , 35, 25)
                                                     text:@"规格:"
                                                textColor:KL_secendTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [self addSubview:guigeLable];
    self.guigeLable = guigeLable;
    
    self.typeLable = [[STLabel alloc] initWithFrame:CGRectMake(guigeLable.right + 5, self.titleLable.bottom+5 , 80, 25)
                                              text:@"1.2"
                                         textColor:KL_secendTextColor
                                              font:12
                                       isSizetoFit:NO
                                     textAlignment:NSTextAlignmentCenter];
    self.typeLable.backgroundColor = BL_backgroundColor;
    self.typeLable.layer.cornerRadius = 5;
    self.typeLable.clipsToBounds = YES;
    [self addSubview:self.typeLable];
    
    self.moneyLable = [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 5, self.typeLable.bottom + 3, UIScreenWidth - 15 - self.iconImageView.right , 25)
                                                text:@"价格:￥20.00"
                                           textColor:KL_redColor
                                                font:13
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];
//    self.moneyLable.attributedText = [self.moneyLable.text st_convertAttributeStringWithKeyWord:@"价格:" attributes:@{NSForegroundColorAttributeName:BL_secendTextColor}];
    [self addSubview:self.moneyLable];
    
    STLabel * numLable = [[STLabel alloc] initWithFrame:CGRectMake(self.titleLable.left, self.moneyLable.bottom , 35, 25)
                                                     text:@"数量:"
                                                textColor:KL_secendTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [self addSubview:numLable];
    
    self.addView = [[STAutoAddView alloc] initWithFrame:CGRectMake(numLable.right + 5, self.moneyLable.bottom, 75, 25)];
    self.addView.titleLable.text = @"1";
    [self addSubview:self.addView];
    

    
}
- (void)setModel:(BLShopCarModel *)model{
    _model = model;
    NSDictionary * dic = model.goods.firstObject;
    if ([dic.allKeys containsObject:@"img_url"]) {
        NSString * url = dic[@"img_url"];
        NSArray * urls = [url componentsSeparatedByString:@","];
        
        [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:urls.firstObject]];
    }
    self.titleLable.text = model.name;
    
   
    
    if ([model.type isEqualToString:@"1"] ) {
        //洗涤
        self.guigeLable.hidden = NO;
        self.typeLable.hidden = NO;
        NSString * menu = @"";
        NSString * cate = @"";
        NSDictionary * dic =  model.goods.firstObject;
        if ([dic.allKeys containsObject:@"cate_id"]) {
            cate = dic[@"cate_id"];
        }
        if ([dic.allKeys containsObject:@"goods_menu_id"]) {
            menu = dic[@"goods_menu_id"];
        }
        self.typeLable.text = [NSString stringWithFormat:@"%@-%@",
                                menu,
                                cate];
        self.titleLable.height = 50;
        self.moneyLable.text = [NSString stringWithFormat:@"会员价:%@",model.price];
    }
    if ([model.type isEqualToString:@"2"] ) {
        //布草酒店定制
        self.typeLable.hidden = NO;
        self.guigeLable.hidden = NO;
        self.titleLable.height = 25;
        NSString * chang = [NSString stringWithFormat:@"%@cm*%@cm",model.leng,model.width];
        self.typeLable.text = chang;
        
        self.moneyLable.text = [NSString stringWithFormat:@"会员价:%@或%@元 + %@积分",
                                model.price,
                                model.score_money,
                                model.make_score];
        
    }
    if ([model.type isEqualToString:@"3"] ) {
        //积分
        self.typeLable.hidden = YES;
        self.guigeLable.hidden = YES;
        self.titleLable.height = 50;
        self.moneyLable.text = [NSString stringWithFormat:@"会员价:%@积分",
                                model.score];
        
    }
    
    if ([model.type isEqualToString:@"4"] ) {
        //采集
        self.typeLable.hidden = YES;
        self.guigeLable.hidden = YES;
        self.titleLable.height = 50;
        self.moneyLable.text = [NSString stringWithFormat:@"会员价:%@或者%@元 + %@积分",
                                model.price,
                                model.score_money,
                                model.make_score];
        
    }
    if ([model.type isEqualToString:@"5"] ) {
        //私人
        self.typeLable.hidden = YES;
        self.guigeLable.hidden = YES;
        self.titleLable.height = 50;
        self.moneyLable.text = [NSString stringWithFormat:@"会员价:%@或%@元 + %@积分",
                                model.price,
                                model.score_money,
                                model.make_score];
        
    }


    self.addView.titleLable.text = model.num;
    
    self.chosedButton.selected = model.isSlected;

}
@end


